package com.endoc.news.fragment.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;

import com.endoc.news.fragment.newslist.view.ViewStatus;

import java.util.List;

public abstract class BaseMvvmFragment<BaseFragmentDataBinding extends ViewDataBinding,BaseFragmentViewModel  extends BaseMvvmViewModel> extends Fragment{
   public BaseFragmentDataBinding mFragmentDataBinding;
    public BaseFragmentViewModel mBaseFragmentViewModel;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mFragmentDataBinding =  DataBindingUtil.inflate(inflater,getLayoutId(),container,false);
        return mFragmentDataBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBaseFragmentViewModel = createViewModel();
        //设置ViewModel的观察,因为ViewModel继承了LifecycleObserver
        getLifecycle().addObserver(mBaseFragmentViewModel);
        //不建议把LiveData放到基类,因为此处的数据类型只能指定一个,正常情况下都会存在多个
      /*  mBaseFragmentViewModel.listMutableLiveData.observe(this,this);
        mBaseFragmentViewModel.mViewStatusMutableLiveData.observe(this,this);*/
    }

    public abstract int getLayoutId();
    public abstract BaseFragmentViewModel createViewModel();
    //public abstract void onNetworkResponse(List<DATA> dataList,boolean isDataUpdated);


}
